package com.czl.module_service.adapter.asset

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.StoreMoveBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemMyAssetStoreApplyListBinding
import com.czl.module_service.fragment.assetUse.MyAssetStoreApplyListFragment

class MyAssetStoreApplyListAdapter(private val fragment: MyAssetStoreApplyListFragment) :
    BaseQuickAdapter<StoreMoveBean, BaseDataBindingHolder<ItemMyAssetStoreApplyListBinding>>(
        R.layout.item_my_asset_store_apply_list
    ) {

    private var moveId : Int? = 0
    private var taskUserId : String = ""
    var tabIndex : Int = 1

    override fun convert(
        holder: BaseDataBindingHolder<ItemMyAssetStoreApplyListBinding>,
        item: StoreMoveBean,
    ) {
        item.applyComment = "调拨原因：" + item.applyComment
        item.aduitStatusName = if (item.aduitStatus == 0) "待审批" else if (item.aduitStatus == 1) "审批通过" else if (item.aduitStatus == 2) "已驳回" else if (item.aduitStatus == 3) "已撤回" else "全部"
        holder.dataBinding?.run {
            data = item
            adapter = this@MyAssetStoreApplyListAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is StoreMoveBean) {
            moveId = it.moveId
            taskUserId = if (tabIndex == 2 && it.processStatus == 1 && it.ttStatus == 2 && it.taskUserId != null) {
                it.taskUserId.toString()
            } else {
                ""
            }
            val bundle = Bundle()
            bundle.putString("moveId", moveId.toString())
            bundle.putString("tabIndex", tabIndex.toString())
            bundle.putString("taskUserId", taskUserId)
            fragment.startContainerActivity(AppConstants.Router.Service.F_SERVICE_ASSET_STORE_APPLY_DETAIL, bundle)
        }
    })
}
